/**
 * Created by guojianyu on 2016/3/24.
 */
myApp.config(function ($routeProvider) {
    $routeProvider.when('/business/viewAll', {
        templateUrl: 'business/viewAll',
        controller: 'businessController'
    })

});
myApp.service('businessListService', function ($http) {
    var doRequest = function () {
        return $http.get('business/listAll');
    }
    return {
        businessList: function () {
            return doRequest();
        }
    };
});
myApp.controller('businessController', function ($scope, $location, $http, businessListService,Notify) {
    /*获取表单数据*/
    businessListService.businessList().success(function (response) {
        $scope.businesses = response;
    });
    /*商家审核状态*/
    $scope.enabled=function(business){
        $scope.data=business;
        $http.post('business/enabled',$scope.data).success(
            function(){
                Notify.success('商家状态已修改为审核已通过');
                businessListService.businessList().success(function (response) {
                    $scope.businesses = response;
                });
            }).error(
            function(){
                Notify.error('error');
            }
        );
    };
    $scope.disabled=function(business){
        $scope.data=business;
        $http.post('business/disabled',$scope.data).success(
            function(){
                Notify.success('商家状态已修改为审核未通过');
                businessListService.businessList().success(function (response) {
                    $scope.businesses = response;
                });
            }
        ).error(
            function(){
                Notify.error('error');
            }
        );
    };
});

